import { Module } from "vuex";
import {doctorlistNurseReq,doctorSearchNurseReq,doctorEditNurseReq} from '@/api/nurse.api'
import { ElMessage } from 'element-plus'
type nurse = {
    total:number | null 
    nurseList:[]
}
const nurseNodule:Module<nurse,any> = {
    state:{
        total:null,
        nurseList:[]
    },
    namespaced: true,
    mutations:{
        M_total(state,payload){
            state.total = payload
        },
        M_nurseList(state,payload){
            state.nurseList = payload
        }
    },
    actions:{
       async A_getNurseList({commit},payload){
            const res = await doctorlistNurseReq(payload)
            console.log(res);
            if(res.data.code === 1){
                commit('M_total',res.data.total)
                commit('M_nurseList',res.data.data)
            }else{
                return res.data.msg
            }
        },
        async A_onSubmit({commit},payload){
            const res = await doctorSearchNurseReq(payload)
            console.log(res);
            if(res.data.code === 1){
                commit('M_total',res.data.total)
                commit('M_nurseList',res.data.data)
            }else{
                return res.data.msg
            }
            
        },
        async A_ediForm({commit},payload){
            const res = await doctorEditNurseReq(payload)
            if(res.data.code === 1){
                ElMessage({
                    message: res.data.msg,
                    type: 'success',
                  })
            }else{
                ElMessage.error(res.data.msg)
            }
            
        }
    }
}

export default nurseNodule